﻿using pTools.cMethods;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace pTools.ChildWin
{
    public partial class SelectProduct : Form
    {
        cMethods.DBHelper db;
        public SelectProduct()
        {
            InitializeComponent();
            db = new cMethods.DBHelper();
        }

        private void SelectProduct_Load(object sender, EventArgs e)
        {
            try
            {
                this.Text = "存货选择";
                loadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void loadData()
        {
            StringBuilder sb = new StringBuilder();
            //sb.Append("select proCode,proName,spec,thickness ");
            sb.Append("select proCode,proName,spec ");
            sb.Append("from fun_Inventory_Info where isdel=0 and status='Y'");
            sb.Append(" and baseCode='" + CommonMethods.baseCode + "' ");
            if (!string.IsNullOrWhiteSpace(tbProcode.Text))
            {
                sb.Append(" and proCode like '%" + tbProcode.Text.Trim() + "%' ");
            }
            if (!string.IsNullOrWhiteSpace(tbProName.Text))
            {
                sb.Append(" and ProName like '%" + tbProName.Text.Trim() + "%' ");
            }
            if (!string.IsNullOrWhiteSpace(tbSpec.Text))
            {
                sb.Append(" and spec like '%" + tbSpec.Text.Trim() + "%' ");
            }
            sb.Append(" order by id asc");
            var table = db.getData(sb.ToString(), "");
            this.dvList.DataSource = table;
            this.dvList.AutoGenerateColumns = false;
        }

        private void btnQuery_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                loadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }



        private void dvList_DoubleClick(object sender, EventArgs e)
        {

            try
            {
                var dic = new Dictionary<string, string>();
                dic["proCode"] = this.dvList.CurrentRow.Cells["ProCode"].Value.ToString();
                dic["proName"] = this.dvList.CurrentRow.Cells["ProName"].Value.ToString();
                dic["spec"] = this.dvList.CurrentRow.Cells["spec"].Value.ToString();
                //dic["thickness"] = this.dvList.CurrentRow.Cells["thickness"].Value.ToString();
                CommonMethods.Parameters = dic;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        private void btnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }
    }
}
